package cn.acewill.yxd.yunxundian.utils;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v4.content.ContextCompat;
import android.view.KeyEvent;

import com.afollestad.materialdialogs.MaterialDialog;

import cn.acewill.yxd.yunxundian.R;

/**
 * Created by XXX on 2017/8/8.
 */

public class MaterialDialogUtils {

    /**
     *含title的弹出框
     * @param context
     * @param title 弹出框标题
     * @param content 弹出框内容
     * @param positiveText 确定按钮
     * @param negativeText 取消按钮
     * @param cancelable 是否取消弹出框外的点击事件，false外部不可点击
     * @param positiveListener 确定的监听
     * @param negativeListener 取消的监听
     */
    public static void showTitleMaterialDialog(Context context, String title, String content, String positiveText, String negativeText,boolean cancelable, MaterialDialog.SingleButtonCallback positiveListener,MaterialDialog.SingleButtonCallback negativeListener){

        new MaterialDialog.Builder(context)
                .title(title)
                .content(content)
                .positiveText(positiveText)
                .negativeText(negativeText)
                .positiveColor(ContextCompat.getColor(context, R.color.blue))
                .negativeColor(ContextCompat.getColor(context, R.color.color_theme))
                .canceledOnTouchOutside(cancelable)
                .onPositive(positiveListener)
                .onNegative(negativeListener)
                .build().show();
    }

    /**
     * 无标题的弹出框
     * @param context
     * @param content
     * @param positiveText
     * @param negativeText
     * @param cancelable
     * @param positiveListener
     * @param negativeListener
     */
    public static void showMaterialDialog(Context context, String content, String positiveText, String negativeText, boolean cancelable, final boolean keyNotcancle, MaterialDialog.SingleButtonCallback positiveListener, MaterialDialog.SingleButtonCallback negativeListener){

        new MaterialDialog.Builder(context)
                .content(content)
                .positiveText(positiveText)
                .negativeText(negativeText)
                .positiveColor(ContextCompat.getColor(context, R.color.blue))
                .negativeColor(ContextCompat.getColor(context, R.color.color_theme))
                .canceledOnTouchOutside(cancelable)
                .onPositive(positiveListener)
                .onNegative(negativeListener)
                .keyListener(new DialogInterface.OnKeyListener() {
                    @Override
                    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                        if (keyCode==KeyEvent.KEYCODE_BACK){
                            return keyNotcancle;
                        }else{
                            return false;
                        }
                    }
                })
                .build().show();
    }

    public static void showMoreBtnDialog(Context context, String content, String positiveText, String netruText, String negativeText,
                                         boolean cancelable, final boolean keyNotcancle, MaterialDialog.SingleButtonCallback positiveListener,
                                         MaterialDialog.SingleButtonCallback netruListener, MaterialDialog.SingleButtonCallback negativeListener){
        new MaterialDialog.Builder(context)
                .content(content)
                .positiveText(positiveText)
                .neutralText(netruText)
                .negativeText(negativeText)
                .positiveColor(ContextCompat.getColor(context, R.color.blue))
                .negativeColor(ContextCompat.getColor(context, R.color.color_theme))
                .neutralColor(ContextCompat.getColor(context,R.color.red))
                .canceledOnTouchOutside(cancelable)
                .onPositive(positiveListener)
                .onNeutral(netruListener)
                .onNegative(negativeListener)
                .keyListener(new DialogInterface.OnKeyListener() {
                    @Override
                    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                        if (keyCode==KeyEvent.KEYCODE_BACK){
                            return keyNotcancle;
                        }else{
                            return false;
                        }
                    }
                })
                .build().show();
    }


}
